package com.neutech.util;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ImageUtil {
    private static final Map<String, Image> imageMap = new HashMap<>();

    static {
        // 读取图片放入map集合
        imageMap.put("bg", getImage("com/neutech/res/background.png"));
        imageMap.put("birds", getImage("com/neutech/res/birds.png"));
        imageMap.put("land", getImage("com/neutech/res/land.png"));
        imageMap.put("pd", getImage("com/neutech/res/pie_down.png"));
        imageMap.put("pu", getImage("com/neutech/res/pie_up.png"));
        imageMap.put("sb", getImage("com/neutech/res/start_button.png"));
    }
    public static Image getImage(String path){
        Image image = null;

        try {
            image = ImageIO.read(ImageUtil.class.getClassLoader().getResourceAsStream(path));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return image;
    }

    public static Image get(String key){
        return imageMap.get(key);
    }
}
